package grow_task

import (
	"go_server/game_server/api/service"
	"go_server/game_server/constants"
	"go_server/game_server/event_manager"
	"go_server/game_server/event_manager/event_data"
	"go_server/zinx/zlog"
)

type GrowTaskService struct {
	service.AbsService

	GetGrowTaskList  *GetGrowTaskListApi
	GetGrowTaskPrize *GetGrowTaskPrizeApi

	eventMethods map[event_data.EventType]func(event event_data.IEvent)
}

var (
	ServiceObj *GrowTaskService

	firstGrowTaskId int32 = 18030001 // 第一个成长任务id
)

func init() {
	ServiceObj = &GrowTaskService{
		GetGrowTaskList:  &GetGrowTaskListApi{},
		GetGrowTaskPrize: &GetGrowTaskPrizeApi{},

		eventMethods: make(map[event_data.EventType]func(event event_data.IEvent)),
	}

	event_manager.EventManagerObj.AddServiceEvent(event_data.DreamSceneBattleEvent, onDreamSceneBattleEvent, ServiceObj) //梦境关卡战斗事件
}

func (s *GrowTaskService) GetModuleName() string {
	return "grow_task"
}

func (s *GrowTaskService) GetEventHandleFunc(eventType event_data.EventType) (func(event event_data.IEvent), bool) {
	eventFunc, ok := s.eventMethods[eventType]
	if !ok {
		zlog.Errorf("GetEventHandleFunc Err!!! method not found!! eventType: %d", eventType)
		return nil, false
	}
	return eventFunc, true
}

func (s *GrowTaskService) GetEventMap() map[event_data.EventType]func(event event_data.IEvent) {
	return s.eventMethods
}

// 梦境关卡战斗事件
func onDreamSceneBattleEvent(event event_data.IEvent) {
	conn := event.GetRoleConn()
	roleId, ok := event.GetRoleId()
	if !ok {
		return
	}

	var taskType int32 = constants.MAIN_TASK                  // 任务类别-主线任务
	var taskEvent1 int32 = constants.DREAM_SCENE_BATTLE_EVENT // 任务事件-战斗次数
	//var taskEvent2 int32 = constants.DREAM_SCENE_BATTLE_STAR_EVENT // 任务事件-指定关卡获得星级

	ServiceObj.S2C_UpdateGrowTask(conn, roleId, taskType, taskEvent1, map[string]int32{
		"id":    0,
		"value": 1, // 完成一次战斗
	})
	//ServiceObj.S2C_UpdateGrowTask(conn, roleId.(int64), taskType, taskEvent2, parms)

	//ServiceObj.GetMainTaskPrize.TestHandle(roleId.(int64))
}
